package dyyx.index;

import java.io.File;
import java.nio.file.Paths;
import java.util.Date;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

import dyyx.file.FileScanUtil;
import dyyx.file.ScanContext;

public class IndexForWebMain {
	
	public static void main(String[] args) throws Exception {
		
		// System.out.println("hello,lucene");
		// 存放索引的目录
		String indexPath = "/Users/dugang/work/lucene2/";
		// 被索引文件目录 
		String docsPath = "/Users/dugang/fun/hellocode/web/docs/";
		
		
		Directory dir = FSDirectory.open(Paths.get(indexPath));
		// Analyzer analyzer = new StandardAnalyzer();
		Analyzer analyzer = new SmartChineseAnalyzer();

		IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
		iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
		IndexWriter writer = new IndexWriter(dir, iwc);
		IndexHandler handler = new IndexHandler(writer);
		ScanContext context = new ScanContext();
		context.handler = handler;
		
		FileScanUtil.doScan(new File(docsPath), context);

		
		writer.flush();
		
		writer.close();
		
		
		System.out.println("index done,wirter close done,"+new Date());
		
		
		
	
	}
}
